$(function () {
  var swiper = new Swiper('.swiper-ten-projects', {
    slidesPerView: 4,
    spaceBetween: 20,
    centeredSlides: true,
    loop: true,
    autoplay: true,
    autoplay: {
      delay: 3000,
      disableOnInteraction: false
    },
    pagination: {
      el: '.swiper-pagination',
      clickable: true,
    },
    navigation: {
      nextEl: '.swiper-ten-projects .swiper-button-next',
      prevEl: '.swiper-ten-projects .swiper-button-prev',
    },
  });

  var swiper2 = new Swiper('.swiper-ten-cases', {
    slidesPerView: 4,
    spaceBetween: 20,
    centeredSlides: true,
    loop: true,
    autoplay: true,
    autoplay: {
      delay: 3000,
      disableOnInteraction: false
    },
    pagination: {
      el: '.swiper-pagination',
      clickable: true,
    },
    navigation: {
      nextEl: '.swiper-ten-cases .swiper-button-next',
      prevEl: '.swiper-ten-cases .swiper-button-prev',
    },
  });

  $(".beautiful-movie .vod").eq(1).css('display', 'none')

  function playVideo(videoNumber) {
    $('video').each(function (e) {
      this.pause();
      if (e === videoNumber) {
        $('video')[e].play()
      } else {
        $('video')[e].pause();
      }
    });
  }

  function stopAllVideo() {
    $('video').each(function (e) {
      $('video')[e].pause()
    });
  }

  var indexnumber = 0;
  $(".beautiful-builder-menusilder li").hover(function () {
    $(this).addClass("active").siblings().removeClass("active");
    indexnumber = $(this).index()
    $(".beautiful-movie .vod").eq(indexnumber).css('display', 'block').siblings().css('display', 'none')
    $("#more a").eq(indexnumber).css('display', 'block').siblings().css('display', 'none')
    indexnumber === 0 ? playVideo(2) : playVideo(3)
  });





  let nav = $(".nav");
  let win = $(window);
  let sc = $(document);
  win.scroll(function () {
    let number = sc.scrollTop()
    console.log(number,"number")
    if (number >= 528) {
      nav.addClass("fixednav");
      $("#nav.navbar").addClass("navbar");
    } else {
      nav.removeClass("fixednav");
    }
    if (number < 841) {
      stopAllVideo()
      $(".nav ul li").removeClass("active");
    }
    if (number >= 841 && number < 1740) {
      $(".nav ul li").eq(0).addClass("active").siblings().removeClass("active");
      playVideo(0)
    }
    if (number >= 1741 && number < 3449) {
      $(".nav ul li").eq(1).addClass("active").siblings().removeClass("active");
      playVideo(1)
    }
    if (number >= 3450 && number < 4726) {
      $(".nav ul li").eq(2).addClass("active").siblings().removeClass("active");
      playVideo(2)
      indexnumber === 0 ? playVideo(2) : playVideo(3)
    }
    if (number >= 4727 && number < 6480) {
      $(".nav ul li").eq(3).addClass("active").siblings().removeClass("active");
      playVideo(4)
    }
    if (number >= 6481 && number < 7617) {
      $(".nav ul li").eq(4).addClass("active").siblings().removeClass("active");
      playVideo(5)
    }
    if (number > 7617) {
      stopAllVideo()
      $(".nav ul li").removeClass("active");
    }
  });

  $(".nav ul li").on("click", function (event) {
    setTimeout(() => $(this).addClass("active").siblings().removeClass("active"), 2000); // 添加延迟以避免快速点击时的闪烁
    const index = $(this).index();
    const scrollToPosition = {
      0: 841,
      1: 1741,
      2: 3450,
      3: 4727,
      4: 6481,
    }[index];
    if (scrollToPosition !== undefined) {
      window.scrollTo({
        top: scrollToPosition,
        behavior: "smooth",
      });
    }
  });

  

  // $('.video-content .btn').on("click", function () {
  //   $('.video').each(function () { this.pause(); });
  //   $('.btn').each(function () {
  //     $(this).css({ "display": "block" });
  //     console.log(this, "this");
  //   });
  //   $(this).css({ "display": "none" });
  //   var video1 = $(this).parent().find('video')[0];
  //   video1.play();
  //   video1.controls = true
  // })


  // var galleryTop = new Swiper('.gallery-top', {
  //   spaceBetween: 10,
  //   navigation: {
  //     nextEl: '.swiper-button-next',
  //     prevEl: '.swiper-button-prev',
  //   },
  //   // thumbs: {
  //   //   swiper: galleryThumbs
  //   // }
  // });


  // $('.swiper-list .list-box').on("click", function () {
  //   let index = $(this).index();
  //   galleryTop.slideTo(index, 500, true);
  // })



  // function getQueryVariable(variable) {
  //   var query = window.location.search.substring(1);
  //   var vars = query.split('&');
  //   for (var i = 0; i < vars.length; i++) {
  //     var pair = vars[i].split('=');
  //     if (decodeURIComponent(pair[0]) === variable) {
  //       return decodeURIComponent(pair[1]);
  //     }
  //   }
  //   return undefined;
  // }
  // let swiperId = getQueryVariable('swiperId');
  // if (swiperId) {
  //   galleryTop.slideTo(swiperId, 0, false);
  //   let img = $('.swiper-wrapper .swiper-slide').eq(swiperId).find('.btn')
  //   img.css({ "display": "none" });
  //   let video = $('.swiper-wrapper .swiper-slide').eq(swiperId).find('video')[0]
  //   video.play();
  //   video.controls = true
  // }
});